package router

import (
	"demos/controller"
	"demos/middleware"
	"github.com/gin-gonic/gin"
)

// SetupRouter 设置路由
func SetupRouter() *gin.Engine {
	r := gin.Default()

	api := r.Group("/api")
	{
		api.POST("/login", controller.Login)
		api.POST("/logout", controller.Logout)
		api.GET("/users", controller.GetUsers)
		api.POST("/users", controller.CreateUser)
		api.PUT("/users/:id", controller.UpdateUser)
		api.DELETE("/users/:id", controller.DeleteUser)
		api.GET("/me", middleware.JWTAuthMiddleware(), controller.GetCurrentUser)
		api.PUT("/me", middleware.JWTAuthMiddleware(), controller.UpdateCurrentUser)
		api.POST("/me/check-password", middleware.JWTAuthMiddleware(), controller.CheckOldPassword)
		api.GET("/minio/upload-url/:ext", middleware.JWTAuthMiddleware(), controller.GetMinioUploadURL)
		api.POST("/posts", middleware.JWTAuthMiddleware(), controller.AddPost)
		api.GET("/posts", controller.GetPostList)
		api.DELETE("/posts/:id", middleware.JWTAuthMiddleware(), controller.DeletePost)
		api.PUT("/posts/:id/approve", middleware.JWTAuthMiddleware(), controller.ApprovePost)
		api.PUT("/posts/:id/reject", middleware.JWTAuthMiddleware(), controller.RejectPost)
		api.PUT("/posts/:id", middleware.JWTAuthMiddleware(), controller.UpdatePost)
		api.GET("/posts/:id", controller.GetPostDetail)
	}

	return r
}
